<template>
	<view class="container">
		<u-cell-group>
			<u-cell-item title="清空缓存" :value="totalCachaSize" @click="askClear"></u-cell-item>
			<!-- <u-cell-item title="消息气泡开关" :arrow="false" hover-class="none"><u-switch slot="right-icon" v-model="checked"></u-switch></u-cell-item> -->
		</u-cell-group>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import Tools from '@/utils/Tools.js';
import Service from '../../utils/Service.js';
import { initCacheSize, clearStorageCache } from '@/store/dispatches.js';
export default {
	data() {
		return {
			checked: false
		};
	},
	computed: {
		...mapState({
			appCacha: state => state.device.cacheSize,
			storageCache: state => state.cache
		}),
		totalCachaSize: function() {
			return Tools.formatSize(JSON.stringify(this.storageCache || {}).length + this.appCacha);
		}
	},

	onShow() {
		initCacheSize();
	},
	methods: {
		askClear() {
			uni.showModal({
				title: '清理缓存',
				content: '清理缓存不会清除用户信息。\n若清理缓存后出现疫情，请联系工作人员或重启应用',
				success: e => {
					if (e.confirm) {
						uni.showLoading({
							title: '正在清理'
						});
						// #ifdef APP-PLUS
						plus.cache.clear(() => {
							setTimeout(() => {
								clearStorageCache();
								uni.hideLoading();
								initCacheSize();
							}, 600);
						});
						// #endif
						// #ifndef APP-PLUS
						setTimeout(() => {
							clearStorageCache();
							uni.hideLoading();
							initCacheSize();
						}, 600);
						// #endif
					}
				}
			});
		}
	}
};
</script>

<style></style>
